 

package com.zdkj.subway.support.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.common.security.util.ObjectUtils;
import com.zdkj.subway.support.entity.SwPmTime;
import com.zdkj.subway.support.service.SwPmTimeService;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 时间类参数表
 *
 * @author cuilei
 * @date 2020-05-29 18:00:44
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swpmtime" )
@Api(value = "swpmtime", tags = "时间类参数表管理")
public class SwPmTimeController {

    private final SwPmTimeService swPmTimeService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param swPmTime 时间类参数表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public R getSwPmTimePage(Page page, SwPmTime swPmTime) {
        return R.ok(swPmTimeService.page(page, Wrappers.query(swPmTime)));
    }

    /**
     * 通过id查询时间类参数表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(swPmTimeService.getById(id));
    }

    /**
     * 新增时间类参数表
     * @param swPmTime 时间类参数表
     * @return R
     */
    @ApiOperation(value = "新增时间类参数表", notes = "新增时间类参数表")
    @SysLog("新增时间类参数表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('support_sw_pm_time_add')" )
    public R save(@RequestBody SwPmTime swPmTime) {
        SwPmTime defaultObj = ObjectUtils.getDefaultObj(SwPmTime.class);
        BeanUtils.copyProperties(swPmTime, defaultObj,
                ObjectUtils.getNullAndEmptyPropertyNames(swPmTime));
        return R.ok(swPmTimeService.save(swPmTime));
    }

    /**
     * 修改时间类参数表
     * @param swPmTime 时间类参数表
     * @return R
     */
    @ApiOperation(value = "修改时间类参数表", notes = "修改时间类参数表")
    @SysLog("修改时间类参数表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('support_sw_pm_time_edit')" )
    public R updateById(@RequestBody SwPmTime swPmTime) {
        return R.ok(swPmTimeService.updateById(swPmTime));
    }

    /**
     * 通过id删除时间类参数表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除时间类参数表", notes = "通过id删除时间类参数表")
    @SysLog("通过id删除时间类参数表" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('support_sw_pm_time_del')" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(swPmTimeService.removeById(id));
    }

}
